﻿<%@ WebHandler Language="C#" Class="SIPO.Web.AjaxHandler.Loaddata.getsanction" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using SIPO.Library.DataAccess.Transaction;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.Enum;
using SIPO.Web.Support;
using Newtonsoft.Json.Linq;

using System.Text;

namespace SIPO.Web.AjaxHandler.Loaddata
{
    public class getsanction : SIPO.Web.BaseHandler
    {
        string MethodName = string.Empty;
        recSanctionRepo recSanctionDal = new recSanctionRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);

        public override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);

            if (context.Request.Params["method"] != null)
            {
                MethodName = context.Request.Params["method"];
                MethodName = MethodName.ToLower();
            }

            if (MethodName == "objection")
            {
                int id = Convert.ToInt32(context.Request.Params["debtor_sector_id"]);
                string tglPermohonan = "01/01/1900";
                if (context.Request.Params["tgl_permohonan"].ToString() != "")
                    tglPermohonan = context.Request.Params["tgl_permohonan"].ToString();
                List<recSanction> result = recSanctionDal.GetListNotInObjection(id, tglPermohonan);

                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));

            }
            else if (MethodName == "getsanctionbyid")
            {
                int id = Convert.ToInt32(context.Request.Params["sanction_id"]);
                recSanction sanction = recSanctionDal.GetById(id);

                StringBuilder sbProject = new StringBuilder();

                sbProject.Append("{");
                sbProject.AppendFormat("  {0}LetterDate{0}:{0}{1}{0}", "\"", sanction.LetterDate.Value.ToString("dd/MM/yyyy"));
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}Value{0}:{0}{1}{0}", "\"", sanction.Value.ToString());
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}LetterNo{0}:{0}{1}{0}", "\"", sanction.LetterNo);
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}BillingNo{0}:{0}{1}{0}", "\"", sanction.BillingNo);
                sbProject.Append("}");

                context.Response.Write(sbProject.ToString());

            }
            else
            {
                int id = Convert.ToInt32(context.Request.Params["sanction_id"]);
                List<recSanction> list = recSanctionDal.GetList();
                var result = list.Where(x => x.SanctionID == id);

                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));

            }
        }

        public override bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}